<template>
  <div class="log_dialog">
    <el-dialog
      :title="dialogData.title"
      @open="dialogOpen"
      @close="dialogClose"
      class="reportDialog"
      :close-on-click-modal="false"
      :visible.sync="dialogData.dialogVisible"
      width="35%"
    >
      <el-form label-width="120px" :model="form" ref="form" :rules="rules">
        <el-form-item label="组织关系" prop="orgid" ref="orgid">
          <el-input
            v-model="form.orgid"
            disabled="disabled"
            @click.native="selectOrg"
          ></el-input>
          <i class="fa fa-sitemap"></i>
        </el-form-item>
        <el-form-item label="任务类型" prop="taskType" ref="taskType">
          <el-select
            placeholder="请选择"
            v-model="form.taskType"
            style="width: 100%"
            @change="seleTaskType"
          >
            <el-option
              v-for="option in taskTypeList"
              :key="option.value"
              :value="option.value"
              :label="option.label"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="软件版本" prop="c" v-show="form.taskType == '1'">
          <el-select
            placeholder="请选择"
            v-model="form.softwareId"
            style="width: 100%"
            @change="selectSoftWare"
          >
            <el-option
              v-for="option in versionList"
              :key="option.softwareVersion"
              :value="option.softwareId"
              :label="option.softwareVersion"
            ></el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="AP版本" prop="d" v-show="form.taskType == 'AP升级'">
          <el-select placeholder="请选择" v-model="form.apVersion" style="width:100%">
            <el-option value="hz">10.1.2</el-option>
          </el-select>
        </el-form-item>-->
        <el-form-item
          label="特征库版本"
          prop="softwareId"
          v-show="form.taskType == '2'"
          :rules="[{ required: true, message: '请选特征库版本' }]"
        >
          <el-select
            placeholder="请选择"
            v-model="form.softwareId"
            style="width: 100%"
            @change="selectSoftWare"
          >
            <el-option
              v-for="option in versionList"
              :key="option.softwareVersion"
              :value="option.softwareId"
              :label="option.softwareVersion"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="立即执行" prop="executeNow">
          <el-switch v-model="form.executeNow"></el-switch>
        </el-form-item>
        <el-form-item
          :rules="[{ required: true, message: '请选择执行时间' }]"
          prop="executionTime"
        >
          <span class="label">执行时间</span>
          <el-date-picker
            v-model="form.executionTime"
            type="datetime"
            :disabled="form.executeNow"
            placeholder="选择日期"
          ></el-date-picker>
        </el-form-item>
      </el-form>
      <el-dialog
        width="35%"
        title="区域管理"
        class="reportDialog"
        :close-on-click-modal="false"
        :visible.sync="areaDialog"
        append-to-body
      >
        <el-tree
          :data="treeData"
          node-key="id"
          ref="tree"
          :props="defaultProps"
          default-expand-all
          highlight-current
          show-checkbox
          @check="checkNodes"
        >
          <span class="custom-tree-node" slot-scope="{ node, data }">
            <el-tooltip
              v-if="node.label.length > 15"
              :content="node.label"
              placement="top"
              effect="light"
            >
              <span>{{ node.label.slice(0, 12) + "..." }}</span>
            </el-tooltip>
            <span v-else>{{ node.label }}</span>
          </span>
        </el-tree>
        <el-row style="text-align: right">
          <el-button type="primary" @click="groupSave">确定</el-button>
          <el-button @click="areaDialog = false">取消</el-button>
        </el-row>
      </el-dialog>
      <el-row style="text-align: right">
        <el-button type="primary" @click="save">确定</el-button>
        <el-button @click="dialogData.dialogVisible = false">取消</el-button>
      </el-row>
    </el-dialog>
  </div>
</template>

<script>
export default {
  mounted() {},
  methods: {
    dialogClose() {
      let that = this;
      that.dialogData.dialogVisible = false;
      //当弹框关闭的时候，组织关系的那个el-tree setCheckedKeys不行，还需要加上节点的。
      var node = this.$refs.tree.getNode(this.treeData[0].id).parent;
      node.childNodes.forEach((item) => {
        node.checked = false;
        if (item.childNodes.length > 0) {
          item.childNodes.forEach((element) => {
            element.checked = false;
          });
        }
      });
      console.log(this.$refs.tree.getNode(this.treeData[0].id).parent);
      that.$nextTick(() => {
        // if (that.$refs.tree) {
        // that.$refs.tree.setCheckedNodes([]);
        that.$refs.tree.setCheckedKeys([]);
        // }
      });
      this.$refs.form.resetFields();
    },
  },
};
</script>

<style>
</style>